# quick_test.py
import requests
import json
from config import Config


def quick_test():
    """快速测试讯飞星火API"""
    print("🚀 快速测试讯飞星火API")

    url = "https://spark-api-open.xf-yun.com/v1/chat/completions"
    headers = {
        "Authorization": f"Bearer {Config.XUNFEI_API_PASSWORD}",
        "Content-Type": "application/json"
    }

    # 使用更简化的提示词
    data = {
        "model": "generalv3.5",
        "messages": [
            {
                "role": "user",
                "content": "请简单回复'食物分析测试成功'"
            }
        ],
        "temperature": 0.7,
        "max_tokens": 50,  # 减少输出长度
        "stream": False
    }

    try:
        print("📡 发送快速测试请求...")
        response = requests.post(url, headers=headers, json=data, timeout=15)

        print(f"📥 状态码: {response.status_code}")

        if response.status_code == 200:
            result = response.json()
            print("✅ 快速测试成功!")
            if 'choices' in result and len(result['choices']) > 0:
                content = result['choices'][0]['message']['content']
                print(f"💬 回复: {content}")
            return True
        else:
            print(f"❌ 快速测试失败: {response.text}")
            return False

    except Exception as e:
        print(f"💥 快速测试异常: {e}")
        return False


if __name__ == "__main__":
    quick_test()